package com.seventh.parkingrent.controller;


import com.seventh.parkingrent.common.Result;
import com.seventh.parkingrent.controller.form.EvaluationForm;
import com.seventh.parkingrent.domain.Evaluation;
import com.seventh.parkingrent.domain.RentMessage;
import com.seventh.parkingrent.service.impl.EvaluationServiceImpl;
import com.seventh.parkingrent.service.impl.RentMessageServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-24
 */
@RestController
@RequestMapping("")
@CrossOrigin("*")
@Slf4j
public class EvaluationController {
    @Autowired
    private EvaluationServiceImpl evaluationService;
    @Autowired
    private RentMessageServiceImpl rentMessageService;

    //新增评价
    @PostMapping("addevaluation")
    public Result addevaluation(@RequestBody EvaluationForm evaluationForm){
        log.info("租赁新增订单评价：{}",evaluationForm);
        Integer rentid = evaluationForm.getRentid();
        RentMessage rentById = rentMessageService.getRentById(rentid);
        Integer zlid = rentById.getZlid();
        if (zlid!=null){
            return Result.fail("已经写过评论了");
        }
        boolean b = evaluationService.addevaluation(evaluationForm);
        return b?Result.success():Result.fail();
    }
    //查看评价
    @GetMapping("seelease")
    public Result seelease(Integer rentid){
        log.info("查看租赁评价订单id{}",rentid);
        Evaluation evaluation = evaluationService.getevaluationByRentid(rentid);
        if(evaluation==null){
            return Result.fail("还没有评论信息哦");
        }
        return Result.success(evaluation);
    }
}

